package com.shu.service.impl;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;

import com.shu.dao.SysRoleMapper;
import com.shu.entity.SysRole;
import com.shu.service.SysUserRoleService;

@Service
public class UserRoleServiceImpl implements SysUserRoleService {
	
	@Autowired
	private SysRoleMapper roleMapper;

	@Override
	public Collection<GrantedAuthority> getRoleByUserName(String account) {
        Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
        for(SysRole role : roleMapper.getRolesByAccount(account)) {
        	GrantedAuthority auth = new SimpleGrantedAuthority(role.getCode());
        	auths.add(auth);
        }
		return auths;
	}

}
